package Finish;

/**
 * Created by fanshaohua on 2017/6/6.
 */

import java.io.*;
import java.util.Properties;

public class GetFileString {
    public String getConfig(String path, String key) {
        InputStream input;
        Properties properties = new Properties();
        try {
            input = new FileInputStream(path);
            properties.load(input);
        } catch (FileNotFoundException e) {
            System.out.println("无法找到配置文件！！");
            e.printStackTrace();
        } catch (IOException e) {
            System.out.println("无法解析该配置文件！！");
        }
        String result = properties.getProperty(key);
        if (result == null) {
            System.out.println("**********" + key + "is not exists!**********");
        }
        return result;
    }

    public void updateProperties(String keyname, String keyvalue) {
        String profilepath = "E:\\Interface_test\\config\\Api_Config.properties";
        Properties prop = new Properties();
        try {
            FileInputStream fis = new FileInputStream(profilepath);
            try {
                prop.load(fis);
                fis.close();
                prop.setProperty(keyname, keyvalue);
                FileOutputStream fos = new FileOutputStream(profilepath);
                prop.store(fos, "Copyright Thcic");
                fos.close();
            } catch (IOException e) {
                e.printStackTrace();
                System.out.println("修改资源文件：" + profilepath + "异常！msg：" + e.getMessage());
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
            System.out.println("无法获得资源文件：" + profilepath);
        }

    }

    public void updatePropertieslong(String keyname, String keyvalue) {
        String profilepath = "E:\\Interface_test\\config\\Api_Config.properties";
        Properties prop = new Properties();
        try {
            FileInputStream fis = new FileInputStream(profilepath);
            try {
                prop.load(fis);
                fis.close();
                prop.setProperty(keyname, String.valueOf(keyvalue));
                FileOutputStream fos = new FileOutputStream(profilepath);
                prop.store(fos, "Copyright Thcic");
                fos.close();
            } catch (IOException e) {
                e.printStackTrace();
                System.out.println("修改资源文件：" + profilepath + "异常！msg：" + e.getMessage());
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
            System.out.println("无法获得资源文件：" + profilepath);
        }

    }

}

